<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Clearsign text</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="gnupg.examples.html">范例</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="ref.gnupg.html">GnuPG 函数</a></div>
 <div class="up"><a href="gnupg.examples.html">范例</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="gnupg.examples-clearsign" class="section">
  <h2 class="title">Clearsign text</h2>
  <p class="para">
   This example will clearsign a given text.
  </p>
  <div class="example" id="example-3397">
   <p><strong>Example #1 gnupg clearsign example (procedural)</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;init&nbsp;gnupg<br /></span><span style="color: #0000BB">$res&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">gnupg_init</span><span style="color: #007700">();<br /></span><span style="color: #FF8000">//&nbsp;not&nbsp;really&nbsp;needed.&nbsp;Clearsign&nbsp;is&nbsp;default<br /></span><span style="color: #0000BB">gnupg_setsignmode</span><span style="color: #007700">(</span><span style="color: #0000BB">$res</span><span style="color: #007700">,</span><span style="color: #0000BB">GNUPG_SIG_MODE_CLEAR</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">//&nbsp;add&nbsp;key&nbsp;with&nbsp;passphrase&nbsp;'test'&nbsp;for&nbsp;signing<br /></span><span style="color: #0000BB">gnupg_addsignkey</span><span style="color: #007700">(</span><span style="color: #0000BB">$res</span><span style="color: #007700">,</span><span style="color: #DD0000">"8660281B6051D071D94B5B230549F9DC851566DC"</span><span style="color: #007700">,</span><span style="color: #DD0000">"test"</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">//&nbsp;sign<br /></span><span style="color: #0000BB">$signed&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">gnupg_sign</span><span style="color: #007700">(</span><span style="color: #0000BB">$res</span><span style="color: #007700">,</span><span style="color: #DD0000">"just&nbsp;a&nbsp;test"</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">$signed</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

  </div>
  <div class="example" id="example-3398">
   <p><strong>Example #2 gnupg clearsign example (OO)</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;new&nbsp;class<br /></span><span style="color: #0000BB">$gnupg&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">gnupg</span><span style="color: #007700">();<br /></span><span style="color: #FF8000">//&nbsp;not&nbsp;really&nbsp;needed.&nbsp;Clearsign&nbsp;is&nbsp;default<br /></span><span style="color: #0000BB">$gnupg</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setsignmode</span><span style="color: #007700">(</span><span style="color: #0000BB">gnupg</span><span style="color: #007700">::</span><span style="color: #0000BB">SIG_MODE_CLEAR</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">//&nbsp;add&nbsp;key&nbsp;with&nbsp;passphrase&nbsp;'test'&nbsp;for&nbsp;signing<br /></span><span style="color: #0000BB">$gnupg</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addsignkey</span><span style="color: #007700">(</span><span style="color: #DD0000">"8660281B6051D071D94B5B230549F9DC851566DC"</span><span style="color: #007700">,</span><span style="color: #DD0000">"test"</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">//&nbsp;sign<br /></span><span style="color: #0000BB">$signed&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$gnupg</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">sign</span><span style="color: #007700">(</span><span style="color: #DD0000">"just&nbsp;a&nbsp;test"</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">$signed</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

  </div>
  <div class="example" id="gnupg.keylistiterator">
   <p><strong>Example #3 keylistiterator</strong></p>
   <div class="example-contents"><p>
    This extension also comes with an Iterator for your keyring.
   </p></div>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;create&nbsp;a&nbsp;new&nbsp;iterator&nbsp;for&nbsp;listing&nbsp;all&nbsp;public&nbsp;keys&nbsp;that&nbsp;matches&nbsp;'example'<br /></span><span style="color: #0000BB">$iterator&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">gnupg_keylistiterator</span><span style="color: #007700">(</span><span style="color: #DD0000">"example"</span><span style="color: #007700">);<br />foreach(</span><span style="color: #0000BB">$iterator&nbsp;</span><span style="color: #007700">as&nbsp;</span><span style="color: #0000BB">$fingerprint&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">$userid</span><span style="color: #007700">){<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">$fingerprint</span><span style="color: #007700">.</span><span style="color: #DD0000">"&nbsp;-&gt;&nbsp;"</span><span style="color: #007700">.</span><span style="color: #0000BB">$userid</span><span style="color: #007700">.</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>
  
  </div>
 </div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="gnupg.examples.html">范例</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="ref.gnupg.html">GnuPG 函数</a></div>
 <div class="up"><a href="gnupg.examples.html">范例</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
